package com.yangjiayu.iot.system.controller;

import com.alibaba.fastjson2.JSON;

import com.yangjiayu.iot.common.result.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/***
 * 模拟登录认证相关接口
 */
@RestController
@RequestMapping("/system/auth")
public class AuthController {

    /**
     * 登录
     * @return
     */
    @PostMapping("login")
    public Result login() {
        Map<String, Object> map = new HashMap<>();
        map.put("token","admin");
        map.put("refresh_token", "");
        return Result.ok(map);
    }

    /**
     * 获取用户权限和信息
     * @return
     */
    @GetMapping("userinfo")
    public Result info() {
        String userinfo = """
                {
                          "id": 1,
                          "name": "admin",
                          "avatar": "https://oss.aliyuncs.com/aliyun_id_photo_bucket/default_handsome.jpg",
                          "role": "",
                          "permissionList": [
                              "sysUser.list",
                              "sysRole.list",
                              "sysMenu.list",
                              "sysOperLog.list",
                              "sysLoginLog.list",
                              "sysUser.add",
                              "sysUser.edit",
                              "sysUser.remove",
                              "sysUser.assignRole",
                              "sysUser.export",
                              "sysRole.add",
                              "sysRole.edit",
                              "sysRole.remove",
                              "sysRole.assignMenu",
                              "sysMenu.add",
                              "sysMenu.edit",
                              "sysMenu.remove",
                              "device.list",
                              "productInfo.list",
                              "deviceInfo.list",
                              "productInfo.add",
                              "productInfo.edit",
                              "productInfo.remove",
                              "deviceInfo.add",
                              "deviceInfo.remove",
                              "devops.list",
                              "debug.list",
                              "deviceOptionLog.list",
                              "dataCount.list"
                          ]
                      }
                                 """;
        return Result.ok(JSON.parseObject(userinfo));
    }

    /**
     * 获取菜单列表
     * @return
     */
    @GetMapping("menus")
    public Result menus() {
        String menus = """
                        [
                            {
                                "title": "系统管理",
                                "name": "system",
                                "children": [
                                    {
                                        "title": "用户管理",
                                        "name": "sysUser",
                                        "children": null
                                    },
                                    {
                                        "title": "角色管理",
                                        "name": "sysRole",
                                        "children": null
                                    },
                                    {
                                        "title": "菜单管理",
                                        "name": "sysMenu",
                                        "children": null
                                    },
                                    {
                                        "title": "日志管理",
                                        "name": "log",
                                        "children": [
                                            {
                                                "title": "操作日志",
                                                "name": "sysOperLog",
                                                "children": null
                                            },
                                            {
                                                "title": "登录日志",
                                                "name": "sysLoginLog",
                                                "children": null
                                            }
                                        ]
                                    }
                                ]
                            },
                            {
                                "title": "设备管理",
                                "name": "device",
                                "children": [
                                    {
                                        "title": "产品",
                                        "name": "productInfo",
                                        "children": null
                                    },
                                    {
                                        "title": "设备",
                                        "name": "deviceInfo",
                                        "children": null
                                    },
                                    {
                                        "title": "查看",
                                        "name": "deviceShow",
                                        "children": null
                                    }
                                ]
                            },
                            {
                                "title": "监控运维",
                                "name": "devops",
                                "children": [
                                    {
                                        "title": "在线调试",
                                        "name": "debug",
                                        "children": null
                                    },
                                    {
                                        "title": "日志服务",
                                        "name": "deviceOptionLog",
                                        "children": null
                                    },
                                    {
                                        "title": "数据统计",
                                        "name": "dataCount",
                                        "children": null
                                    }
                                ]
                            }
                        ]
                        """;
        return Result.ok(JSON.parseArray(menus));
    }
}